package com.mlizhi.modules.spec.dao;


import java.util.Date;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import com.mlizhi.base.dao.AbstractDao;
import com.mlizhi.base.dao.Property;
import com.mlizhi.base.dao.internal.DaoConfig;
import com.mlizhi.modules.spec.dao.model.ContentModel;
import com.mlizhi.modules.spec.dao.model.DetectModel;



public class ContentDao  extends AbstractDao<ContentModel, Long>{

	public static final String TABLENAME = "CONTENT_MODEL";
	
	

    /**
     * Properties of entity Note.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property ContentTitle = new Property(1, String.class, "contentTitle", true, "CONTENT_TITLE");
        public final static Property ContentSummarize = new Property(2, String.class, "contentSummarize", true, "CONTENT_SUMMARIZE");
        public final static Property ContentImageUrl = new Property(3, String.class, "contentImageUrl", true, "CONTENT_IMAGE_URL");
        public final static Property ContentPraise= new Property(4, String.class, "contentPraise", false, "CONTENT_PRAISE");
        public final static Property ContentView = new Property(5, String.class, "contentView", false, "CONTENT_VIEW");
        public final static Property ContentComment = new Property(6, String.class, "contentComment", false, "CONTENT_COMMENT");
        public final static Property ContentInsertTime = new Property(7, java.util.Date.class, "contentInsertTime", false, "CONTENT_INSERT_TIME");
        public final static Property ContentType = new Property(8, Integer.class, "contentType", false, "CONTENT_TYPE");
        public final static Property ContentId = new Property(9, String.class, "contentId", false, "CONTENT_ID");
    };

    public ContentDao(DaoConfig config) {
        super(config);
    }
    
    public ContentDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "'CONTENT_MODEL' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'CONTENT_TITLE' TEXT ," + // 1: contentTitle
                "'CONTENT_SUMMARIZE' TEXT ," + // 2: contentSummarize
                "'CONTENT_IMAGE_URL' TEXT ," + // 3: contentImageUrl
                "'CONTENT_PRAISE' TEXT ," + // 4: contentPraise
                "'CONTENT_VIEW' TEXT ," + // 5: contentView
                "'CONTENT_COMMENT' TEXT ," + // 6: contentComment
                "'CONTENT_INSERT_TIME' INTEGER," +// 7: contentInsertTime
                "'CONTENT_TYPE' INTEGER," +//8: contentType
                "'CONTENT_ID' TEXT);"); //9: contentId
    }

    
	
    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'CONTENT_MODEL'";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, ContentModel entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);//id
        }
        stmt.bindString(2, (entity.getContentTitle()==null?"":entity.getContentTitle()));//contentTitle
        stmt.bindString(3, (entity.getContentSummarize()==null?"":entity.getContentSummarize()));//contentSummarize
        stmt.bindString(4, (entity.getContentImageUrl()==null?"":entity.getContentImageUrl()));//contentImageUrl
        stmt.bindString(5, (entity.getContentPraise()==null?"":entity.getContentPraise()));//contentPraise
        stmt.bindString(6, (entity.getContentView()==null?"":entity.getContentView()));//contentView
        stmt.bindString(7, (entity.getContentComment()==null?"":entity.getContentComment()));//contentComment
        java.util.Date date = entity.getContentInsertTime();//contentInsertTime
        if (date != null) {
            stmt.bindLong(8, date.getTime());
        }
        stmt.bindLong(9, (entity.getContentType()==null?-1l:entity.getContentType()));
        stmt.bindString(10, (entity.getContentId()==null?"":entity.getContentId()));
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    
    /** @inheritdoc */
    @Override
    public ContentModel readEntity(Cursor cursor, int offset) {
    	ContentModel entity = new ContentModel(
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0),//id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1),//contentTitle
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2),//contentSummarize
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3),//contentImageUrl
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4),//contentPraise
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5),//contentView
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6),//contentComment
            cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)),//contentInsertTime
            cursor.isNull(offset + 8) ? -1 : cursor.getInt(offset+8),//contentComment
    	    cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));//contentId
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, ContentModel entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setContentTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setContentSummarize(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setContentImageUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setContentPraise(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setContentView(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setContentComment(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setContentInsertTime(cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)));
        entity.setContentType(cursor.isNull(offset + 8) ? -1 : cursor.getInt(offset+8));
        entity.setContentId(cursor.isNull(offset + 9) ? null : cursor.getString(offset+9));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(ContentModel entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(ContentModel entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
	
}
